/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Br.Com.Cds.Academia.View;

import Br.Com.Cds.Academia.Modalidade.ModalidadeBean;
import Br.Com.Cds.Academia.Modalidade.ModalidadeControl;
import java.awt.Dimension;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author p
 */
public class TelaCadastroModalidade extends javax.swing.JFrame {
    
    DefaultTableModel tmModalidades = new DefaultTableModel(null,new String[]{"Modalidade"}); 
    ListSelectionModel lsmModalidades; 
    String tipoCadastro; 
    List <ModalidadeBean> modalidades;
    
        private void listarModalidades(){ 

        ModalidadeControl gru = new ModalidadeControl();
        modalidades = gru.listarModalidades("%" + TFPesquisar.getText().trim() + "%");
        mostrarModalidades(modalidades);

    }
        
        private void mostrarModalidades(List<ModalidadeBean> modalidades){ 
        if ( modalidades.size()==0){                        
            tmModalidades.setRowCount(0);
            JOptionPane.showMessageDialog(this,"Registro Não Encontrado!","CDS ACADEMIA",JOptionPane.INFORMATION_MESSAGE);
        }else{                                       
            while(tmModalidades.getRowCount() > 0){
                  tmModalidades.removeRow(0);

            }
            String[] campos = new String[] { null}; 
            for (int i = 0;i < modalidades.size(); i++){   
                tmModalidades.addRow(campos);               
                tmModalidades.setValueAt(modalidades.get(i).getNome(),i,0);
  
            }
        }

    }

         private void tbModalidadesLinhaSelecionada(JTable tb){     

        if(tb.getSelectedRow() != -1){                      
            TFNome.setText(modalidades.get(tb.getSelectedRow()).getNome());
            
            String pegaStatus = modalidades.get(tb.getSelectedRow()).getStatus(); 
            if(pegaStatus.equals("ATIVO")){                
               JRBAtivo.setSelected(true);
               JRBInativo.setSelected(false);
            }else if(pegaStatus.equals("INATIVO")){
               JRBInativo.setSelected(true);
               JRBAtivo.setSelected(false);
            }

            BTAlterar.setEnabled(true);    
            BTNovo.setEnabled(true);       
            BTSalvar.setEnabled(false);


       }else{ // Se não houver nenhuma linha selecionada, deixa os campos em branco.
          
            TFNome.setText("");
            JRBAtivo.setSelected(false);
            JRBInativo.setSelected(false);
            BTAlterar.setEnabled(false);

       }

    }
         
         public void limpaTabela(){  
    DefaultTableModel tblRemove = (DefaultTableModel)TBModalidades.getModel();  
      
    if (tblRemove.getRowCount() > 0){  
        for (int i=1;i<=tblRemove.getRowCount();i++){  
            tblRemove.removeRow(0);  
        }              
    }  
  
}  
          
         private JTable getJTable() {        //Metódo para definir o tamanho das colunas na JTable.
     if (TBModalidades == null) {
         TBModalidades = new JTable(tmModalidades);
         defineRenderers();
   }       return TBModalidades;
   
 }
         
          private void defineRenderers() {
     DefaultTableCellRenderer rendererCentro = new DefaultTableCellRenderer();
     rendererCentro.setHorizontalAlignment(SwingConstants.CENTER);
     DefaultTableCellRenderer rendererDireita = new DefaultTableCellRenderer();
     rendererDireita.setHorizontalAlignment(SwingConstants.RIGHT);
     DefaultTableCellRenderer rendererEsquerda = new DefaultTableCellRenderer();
     rendererEsquerda.setHorizontalAlignment(SwingConstants.LEFT);

     JTableHeader header = TBModalidades.getTableHeader();
     header.setPreferredSize(new Dimension(0, 35));
     TableColumnModel modeloDaColuna = TBModalidades.getColumnModel();
     
    // Aqui se define se o texto vai ficar no meio ou nos cantos da coluna.
     
     modeloDaColuna.getColumn(0).setCellRenderer(rendererCentro); 

   // Aqui se define o tamanho das colunas.
     
     modeloDaColuna.getColumn(0).setMaxWidth(1000);

 }
          
          private void novaModalidade(){ // Metodo para quando clicar no botão novo, habilitar e limpar os campos

      TFNome.setText("");
      JRBAtivo.setSelected(false);
      JRBInativo.setSelected(false);
      BTAlterar.setEnabled(false);
      habilitarCampos();
      
     }
    
     private void limparCampos(){

      TFNome.setText("");
      JRBAtivo.setSelected(false);
      JRBInativo.setSelected(false);      

    }
     
     private boolean verificarCampos(){

        if(!TFNome.getText().trim().equals("")){
            return true;
        }
        JOptionPane.showMessageDialog(this,"INFORME O NOME DA MODALIDADE !","CDS ACADEMIA",JOptionPane.WARNING_MESSAGE);
        return false;

    }
     
     private void cadastramModalidade(){ 

         if(verificarCampos() ){ 

            ModalidadeControl gc = new ModalidadeControl();
            ModalidadeBean gb = new ModalidadeBean();

            gb.setNome(TFNome.getText().trim()); 
            if(JRBAtivo.isSelected()){ 
            gb.setStatus("ATIVO");
            }else if(JRBInativo.isSelected()){
            gb.setStatus("INATIVO");
            }else{
            JOptionPane.showMessageDialog(null,"INFORME O STATUS!","CDS ACADEMIA",JOptionPane.WARNING_MESSAGE);
            }

            gc.cadastrarModalidades(gb);
            BTNovo.setEnabled(true);
            limpaTabela();
            TFPesquisar.setText("");
            JOptionPane.showMessageDialog(null,"MODALIDADE CADASTRADA COM SUCESSO","MENSAGEM DO PROGRAMA",JOptionPane.INFORMATION_MESSAGE);
            desabilitarCampos();

         }
        }
     
     private void alteraModalidade(){

         if(verificarCampos() ){ 

            ModalidadeControl gc = new ModalidadeControl();
            ModalidadeBean gb = new ModalidadeBean();

            gb.setNome(TFNome.getText().trim());
            gb.setIdModalidade(modalidades.get(TBModalidades.getSelectedRow()).getIdModalidade()); 
            if(JRBAtivo.isSelected()){
            gb.setStatus("ATIVO");
            }else if(JRBInativo.isSelected()){
            gb.setStatus("INATIVO");
            }else{
            JOptionPane.showMessageDialog(null,"INFORME O STATUS!","CDS ACADEMIA",JOptionPane.WARNING_MESSAGE);
            }

            gc.alterarModalidades(gb);
            BTNovo.setEnabled(true);
            limpaTabela();
            TFPesquisar.setText("");
            JOptionPane.showMessageDialog(null,"MODALIDADE ALTERADA COM SUCESSO","MENSAGEM DO PROGRAMA",JOptionPane.INFORMATION_MESSAGE);
            desabilitarCampos();

         }
        }
     
     
     private void excluirModalidade(){

        if(TBModalidades.getSelectedRow() != -1){
         int resposta = JOptionPane.showConfirmDialog(this,"Excluir Registro Selecionado ?","CONFIRMAÇÂO",JOptionPane.YES_NO_OPTION);
            if(resposta == JOptionPane.YES_OPTION){
                ModalidadeControl gc = new ModalidadeControl();
                gc.excluirModalidade(modalidades.get(TBModalidades.getSelectedRow()).getIdModalidade());
                limpaTabela();
                TFNome.setText("");
                TFPesquisar.setText("");

            }
        }
    }
     
     private void habilitarCampos(){

     TFNome.setEditable(true);
     JRBAtivo.setEnabled(true);
     JRBInativo.setEnabled(true);
   }

    private void desabilitarCampos(){

     TFNome.setEditable(false);
     JRBAtivo.setEnabled(false);
     JRBInativo.setEnabled(false);

  }
    /**
     * Creates new form TelaCadastroAluno
     */
    public TelaCadastroModalidade() {
        initComponents();
        defineRenderers();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jTextField1 = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jToggleButton1 = new javax.swing.JToggleButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        TFPesquisar = new javax.swing.JTextField();
        BTPesquisar = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        TFNome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jToolBar3 = new javax.swing.JToolBar();
        jPanel7 = new javax.swing.JPanel();
        JRBAtivo = new javax.swing.JRadioButton();
        JRBInativo = new javax.swing.JRadioButton();
        jToolBar1 = new javax.swing.JToolBar();
        BTNovo = new javax.swing.JButton();
        BTAlterar = new javax.swing.JButton();
        BTSalvar = new javax.swing.JButton();
        BTExcluir = new javax.swing.JButton();
        BTCancelar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        TBModalidades = new javax.swing.JTable();

        jTextField1.setText("jTextField1");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Foto", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 127, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 140, Short.MAX_VALUE)
        );

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jToggleButton1.setText("jToggleButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("CADASTRO DE MODALIDADE");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        jLabel1.setFont(new java.awt.Font("Yu Gothic", 1, 14)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/exercicio 2.png"))); // NOI18N
        jLabel1.setText("CADASTRO DE MODALIDADE");

        TFPesquisar.setToolTipText("Digite o Nome da Modalidade");

        BTPesquisar.setFont(new java.awt.Font("Yu Gothic", 0, 12)); // NOI18N
        BTPesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Find.png"))); // NOI18N
        BTPesquisar.setText("Pesquisar");
        BTPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTPesquisarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(TFPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BTPesquisar)
                .addGap(18, 18, 18))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TFPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BTPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel13.setFont(new java.awt.Font("Yu Gothic", 0, 12)); // NOI18N

        jTabbedPane1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        TFNome.setEditable(false);
        TFNome.setToolTipText("Nome da Modalidade");

        jLabel4.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        jLabel4.setText("NOME:");

        jToolBar3.setBackground(new java.awt.Color(255, 255, 255));
        jToolBar3.setFloatable(false);
        jToolBar3.setRollover(true);

        jPanel7.setBackground(new java.awt.Color(255, 255, 255));
        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "STATUS", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Yu Gothic", 1, 12))); // NOI18N

        JRBAtivo.setBackground(new java.awt.Color(255, 255, 255));
        JRBAtivo.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        JRBAtivo.setText("ATIVO");
        JRBAtivo.setToolTipText("Modalidade Ativa");
        JRBAtivo.setEnabled(false);
        JRBAtivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRBAtivoActionPerformed(evt);
            }
        });

        JRBInativo.setBackground(new java.awt.Color(255, 255, 255));
        JRBInativo.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        JRBInativo.setText("INATIVO");
        JRBInativo.setToolTipText("Modalidade Inativa");
        JRBInativo.setEnabled(false);
        JRBInativo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRBInativoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JRBAtivo)
                    .addComponent(JRBInativo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JRBAtivo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JRBInativo)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(69, 69, 69)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(TFNome, javax.swing.GroupLayout.PREFERRED_SIZE, 451, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(125, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(TFNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("MODALIDADE", jPanel3);

        jToolBar1.setBorder(null);
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        BTNovo.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Add.png"))); // NOI18N
        BTNovo.setText("Novo");
        BTNovo.setFocusable(false);
        BTNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTNovoActionPerformed(evt);
            }
        });
        jToolBar1.add(BTNovo);

        BTAlterar.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Modify.png"))); // NOI18N
        BTAlterar.setText("Alterar");
        BTAlterar.setFocusable(false);
        BTAlterar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTAlterar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTAlterarActionPerformed(evt);
            }
        });
        jToolBar1.add(BTAlterar);

        BTSalvar.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Apply.png"))); // NOI18N
        BTSalvar.setText("Salvar");
        BTSalvar.setFocusable(false);
        BTSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTSalvarActionPerformed(evt);
            }
        });
        jToolBar1.add(BTSalvar);

        BTExcluir.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Erase.png"))); // NOI18N
        BTExcluir.setText("Excluir");
        BTExcluir.setFocusable(false);
        BTExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTExcluirActionPerformed(evt);
            }
        });
        jToolBar1.add(BTExcluir);

        BTCancelar.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/No.png"))); // NOI18N
        BTCancelar.setText("Cancelar");
        BTCancelar.setFocusable(false);
        BTCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTCancelarActionPerformed(evt);
            }
        });
        jToolBar1.add(BTCancelar);

        TBModalidades.setFont(new java.awt.Font("Yu Gothic", 0, 12)); // NOI18N
        TBModalidades.setModel(tmModalidades);
        TBModalidades.setToolTipText("Modalidades");
        TBModalidades.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmModalidades = TBModalidades.getSelectionModel();
        lsmModalidades.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(!e.getValueIsAdjusting()){
                    tbModalidadesLinhaSelecionada(TBModalidades);
                }
            }
        });
        jScrollPane2.setViewportView(TBModalidades);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel13)
                .addGap(152, 152, 152))
            .addGroup(layout.createSequentialGroup()
                .addGap(290, 290, 290)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addComponent(jLabel13)
                .addContainerGap())
        );

        setSize(new java.awt.Dimension(848, 503));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void BTNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTNovoActionPerformed
    tipoCadastro = "novo"; 
    novaModalidade();
    JRBAtivo.setSelected(true);        
    }//GEN-LAST:event_BTNovoActionPerformed

    private void BTPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTPesquisarActionPerformed
        listarModalidades();
        limparCampos();
        novaModalidade();
        desabilitarCampos();
        BTNovo.setEnabled(true);
        BTAlterar.setEnabled(true);
    }//GEN-LAST:event_BTPesquisarActionPerformed

    private void BTSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTSalvarActionPerformed
if(tipoCadastro.equals("novo")){
        cadastramModalidade();
    }else if (tipoCadastro.equals("alteracao")){
        alteraModalidade();
    }
        limparCampos();      
    }//GEN-LAST:event_BTSalvarActionPerformed

    private void BTAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTAlterarActionPerformed
 tipoCadastro = "alteracao";
 BTSalvar.setEnabled(true);
 habilitarCampos();          
    }//GEN-LAST:event_BTAlterarActionPerformed

    private void BTExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTExcluirActionPerformed
excluirModalidade();       
    }//GEN-LAST:event_BTExcluirActionPerformed

    private void BTCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTCancelarActionPerformed
    novaModalidade();
    desabilitarCampos();
    BTAlterar.setEnabled(true);
    BTNovo.setEnabled(true);
    JRBAtivo.setSelected(false);      
    }//GEN-LAST:event_BTCancelarActionPerformed

    private void JRBAtivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRBAtivoActionPerformed
if(JRBAtivo.isSelected()){
   JRBInativo.setSelected(false);    
    }      
    }//GEN-LAST:event_JRBAtivoActionPerformed

    private void JRBInativoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRBInativoActionPerformed
if(JRBInativo.isSelected()){
   JRBAtivo.setSelected(false);
    }
    }//GEN-LAST:event_JRBInativoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroModalidade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroModalidade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroModalidade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroModalidade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaCadastroModalidade().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTAlterar;
    private javax.swing.JButton BTCancelar;
    private javax.swing.JButton BTExcluir;
    private javax.swing.JButton BTNovo;
    private javax.swing.JButton BTPesquisar;
    private javax.swing.JButton BTSalvar;
    private javax.swing.JRadioButton JRBAtivo;
    private javax.swing.JRadioButton JRBInativo;
    private javax.swing.JTable TBModalidades;
    private javax.swing.JTextField TFNome;
    private javax.swing.JTextField TFPesquisar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar3;
    // End of variables declaration//GEN-END:variables
}
